package managedbean.CRM.SaleOrder; 
 
import entity.CRM.Customer;
import entity.CRM.SaleOrder;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ViewScoped; 
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.CRM.SaleOrderBeanLocal;
 
@ManagedBean(name="viewCustomersSaleOrdersManagerBean")
@ViewScoped 
public class ViewCustomersSaleOrdersManagerBean implements Serializable{ 
    @EJB 
    private SaleOrderBeanLocal saleOrderBeanLocal; 
    
    private Customer selectedCustomer;
    private SaleOrder selectedSaleOrder;
    private List<SaleOrder> saleOrders;
    
    public ViewCustomersSaleOrdersManagerBean() { 
    } 
 
    public void initView()
    {
        if(selectedCustomer==null){
                selectedCustomer = (Customer) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedCustomer");           
        this.setSaleOrders(selectedCustomer.getSaleOrders());
    }
    }
        
    public void makeCashInAdvance(ActionEvent event) throws IOException
    {
        if (selectedSaleOrder !=null)
        {
            System.out.println("b4:"+selectedSaleOrder.getId());
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedSaleOrder", selectedSaleOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("../cashInAdvance/addCashInAdvance.xhtml");                
        }
    }

    public List<SaleOrder> getSaleOrders() {
        return saleOrders;
    }

    public void setSaleOrders(List<SaleOrder> saleOrders) {
        this.saleOrders = saleOrders;
    }

    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

    public SaleOrder getSelectedSaleOrder() {
        return selectedSaleOrder;
    }

    public void setSelectedSaleOrder(SaleOrder selectedSaleOrder) {
        this.selectedSaleOrder = selectedSaleOrder;
    }
}
    
